package com.wing.product.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.product.dao.ProcessDeviceDao;
import com.wing.product.model.entity.ProcessDevice;
import com.wing.product.model.request.ProcessDeviceForm;
import com.wing.product.model.response.ProcessDeviceVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * -ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class ProcessDeviceServiceImpl extends ServiceImpl<ProcessDeviceDao, ProcessDevice> implements ProcessDeviceService {

    @Override
    public int add(ProcessDeviceForm processDeviceForm) {

        //校验

        ProcessDevice processDevice =new ProcessDevice();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(ProcessDevice.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(processDeviceForm, processDevice, copyOptions);

        return baseMapper.insert(processDevice);
    }

    @Override
    public List<ProcessDeviceVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<ProcessDeviceVO> pageList4app(Page page, Map<String, Object> params) {
        List<ProcessDeviceVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public ProcessDeviceVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Transactional
    @Override
    public int delBatch(Long[] ids) {
        if(ids!=null){
            return baseMapper.deleteBatchIds(Arrays.asList(ids));
        }
        return 0;
    }
}
